package com.Policing.Adapter;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.Policing.R;
import com.Policing.bean.look_image_bean;

import java.util.List;

/**
 * Created by Administrator on 2019/5/10.
 */

public class look_image_adap extends ArrayAdapter {
    private Dialog dialog;
    public look_image_adap(Context context, int resource, List<look_image_bean> objects) {

        super(context, resource, objects);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final look_image_bean linkeMain = (look_image_bean)getItem(position);
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.look_image, null);
        TextView text = (TextView) view.findViewById(R.id.text);
        ImageView images = (ImageView)view.findViewById(R.id.images);
        images.setImageBitmap(linkeMain.getImages());
        text.setText(linkeMain.getText());
        images.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //展示在dialog上面的大图
                dialog = new Dialog(getContext(), R.style.FullActivity);
                WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
                attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
                attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(attributes);
                ImageView imageView= new ImageView(getContext());
                imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                imageView.setImageBitmap(linkeMain.getImages());
                dialog.setContentView(imageView);
                //大图的点击事件（点击让他消失）
                dialog.show();
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
            }
        });
        return view;
    }
}
